package moduloIndexacion.analizador;

import java.io.FileInputStream;

import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFShape;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.poi.xslf.usermodel.XSLFTextParagraph;
import org.apache.poi.xslf.usermodel.XSLFTextRun;
import org.apache.poi.xslf.usermodel.XSLFTextShape;

import entidades.Extension;

public class AnalizadorPowerPoint_pptx extends TemplateAnalizador{
	
	public AnalizadorPowerPoint_pptx(){		
		super.extension = new Extension ("pptx","Microsoft PowerPoint Versiones Post 2007");
	}
	
	@Override
	protected String obtenerTexto() {		
		String rutaAcceso = documento.getUbicacion()+documento.getNombre();
		String textoPowerPoint="";
		
		XMLSlideShow pptx;
		try 
		{
			pptx = new XMLSlideShow(new FileInputStream(rutaAcceso));
			for(XSLFSlide slide : pptx.getSlides()){
	            
				textoPowerPoint += " ";				
				//XSLFNotes nota = slide.getNotes();
				//System.out.println("N O T A S " + nota.toString());
																	
	            for(XSLFShape shape : slide.getShapes())
	            {	          
	                if(shape instanceof XSLFTextShape) 
	                {
	                    XSLFTextShape tsh = (XSLFTextShape)shape;
	                    
	                    for(XSLFTextParagraph p : tsh)
	                    {
	                        	                    	
	                        for(XSLFTextRun r : p)
	                        {	                            
	                            textoPowerPoint += r.getText(); 
	                        }
	                    }
	                }
	                
	              
	            }
	        }
		}
		catch (Exception e) {
			System.out.println("ERROR: "+e.toString());
			return null;
		}

        
		return textoPowerPoint;
	}
}